Skip to content

feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations - #37256

Queued
objectstack-fleet[bot] wants to merge 9 commits into
mainfrom
claude/issue-37097-knowledge-org-filter
Queued

objectstack-fleet[bot] wants to merge 9 commits into
mainfrom
claude/issue-37097-knowledge-org-filter

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ
Fixes #37097

repo:objectstack#4 · os-justin · session_01QSeKYkS1d2QkEUgqhneuU1

Clause-②: yes
Metadata-protocol: added
Skills-docs: none — no skill under skills/** teaches KnowledgeDocument, AdapterSearchOptions or the adapter contract suite; skills/objectstack-ai/SKILL.md teaches KnowledgeSource authoring only. content/docs/protocol/knowledge.mdx gains the members and an "Organization scope" section here.

维护者速读

  • 多组织部署里,知识检索只在提问人所属组织的文档里排名,别的组织的文档不再挤占前几名;单组织部署无感。
  • 属于「知识检索平台化」专题第二阶段:索引文档记下所属组织,检索时由平台按部署的租户形态算出提问人的组织交给存储先过滤。
  • 出错时最坏是某些文档在检索里排不上(尚未重建索引的旧文档在多组织形态下要等一次完整重建);能否返回仍由按提问人身份回查记录决定,可直接撤回本改动。
  • 无。

What changes

ADR-0161 K8, item 9, with knowledge-memory as its first reader:

  1. KnowledgeDocument.organizationId? (packages/spec/src/ai/knowledge-document.zod.ts). The service sets it when it assembles a document from a record: the record's organization_id under the group and isolated postures. It is absent under single, for file / http sources and for a record with no organization. indexDocument refuses a caller-supplied value, as it refuses a caller-supplied docHash. The TSDoc also says that an adapter storing docHash stores organizationId from the same version on.

  2. AdapterSearchOptions.organizationIds? (packages/spec/src/contracts/knowledge-adapter.ts). The service computes it per object source in knowledge-organization-scope.ts and derives nothing itself:

    • the posture is the effective one, classifyAdmissionTenancyPosture over the kernel's tenancy service. KnowledgeServicePlugin wires it as the new resolveTenancyPosture option, next to resolveSecurity; the mount logic is untouched. The wiring is pinned through real kernels (LiteKernel and ObjectKernel): walled, no tenancy service, and a tenancy service that cannot be read;
    • the organization set is computeTenantLayer0Verdict (@objectstack/core) for the source's object, over the context's tenantId / accessible_org_ids. isolated gives the active organization and group the deduplicated membership set. A deny verdict becomes []; none (an object outside tenancy, or with no organization_id column) gives no filter;
    • no filter under single, for the system identity and for file / http sources.

    The TSDoc spells out the three cases: absent means no filter, a set means filter before ranking, [] means rank nothing (never "no filter").

  3. knowledge-memory stores organizationId and filters by organizationIds before it scores, so topK is filled from in-scope documents only.

  4. The permission re-read is unchanged and remains the access decision. Nothing new is logged or returned about how many hits a filter removed.

  5. docHash covers organizationId only when the document has one. DOC_HASH_VERSION stays v1, so a document without an organization hashes byte-for-byte as before (pinned against the old recipe).

  6. A posture that cannot be read (a tenancy service is registered but unreadable): a search leaves every object source unsearched for that call and logs at error; a reindex stops before writing and returns ok: false with the reason. An event sync logs at warn with the reason and leaves the stored document as it was (no upsert, no delete; pinned).

  7. Contract suite (@objectstack/service-knowledge/testing): implements.organizationIds is required, which is fine because the suite has not been released yet. It adds adapter-only cases and cases through a real KnowledgeService under isolated, group and single, plus the upgrade case for documents indexed before this change.

PM mechanism assumptions, measured

  • Computed server-side only. KnowledgeSearchOptions has no organization member, and the service builds organizationIds itself. A caller's opaque filter: { organizationIds: [...] } stays inside filter (pinned), and search_knowledge's closed input set refuses an organizationIds argument (pinned). The only callers are the MCP bridges through knowledgeTools(); no REST route reaches search.
  • [] and absent are different. [] filters to nothing in the TSDoc, in knowledge-memory and in the suite. Under isolated with no active organization, and under group with no membership, the adapter is handed [] (pinned).
  • Documents indexed before this change carry no organizationId. Behind a wall a filtered search excludes them until a complete reindex writes them again. Their hash changes once the organization is included, so that reindex does not skip them. Under single nothing changes. This is documented in the TSDoc, the protocol doc and the changeset, and tested in the contract suite ("a document indexed without its organization is not ranked behind a wall until a complete reindex writes it again").
  • runKnowledgeAdapterContract was extended, not a memory-only test.

Tests

Local runs on the final head 6e978db (origin/main d62f9e9 merged; two commits since 3df745d add tests and a TSDoc sentence)
  • pnpm --filter @objectstack/knowledge-memory exec vitest run: Test Files 2 passed, Tests 29 passed.
  • pnpm --filter @objectstack/service-knowledge exec vitest run: Test Files 8 passed, Tests 197 passed.
  • pnpm --filter @objectstack/service-knowledge --filter @objectstack/knowledge-memory run typecheck: exit 0 (tsc + test-typecheck, 0 debt).
  • pnpm --filter @objectstack/spec build && … check:generated: "All 14 generated artifacts are up to date". Before the merge, one artifact was stale (check:docs) and was regenerated with --fix. That diff is the organizationId row and the docHash description in content/docs/references/ai/knowledge-document.mdx. authorable-surface/ai.json gained ai/KnowledgeDocument:organizationId from the spec build.
Derived gate families (dispatch-gates --commands, 117), with --ran reconciliation
  • Run at a8d8915: 113 exit 0. pnpm check:system-context-census exited 1 because the new organization scoping held two system-identity elevation reads with no row on the system-context page. Fixed at 44494ec by moving the scoping under admitSources' existing system bypass (row 46). The system identity's search therefore skips the organization filter through the one read the page already documents, and the census reads OK (202 sites, register matches).
  • Re-run at 44494ec, all exit 0: system-context-census, startup-registry-verdict, type-check-coverage, type-check-debt, test-source-alias, cross-package-test-inputs, undeclared-dep-imports, issue-citations, optional-error-sink, logger-receiver-detach, nul-bytes, doc-authoring, engine-double-contract, tenant-chokepoint, tenant-audit-census, org-identifier.
  • NOT MEASURED (exit 3, prerequisite): check-plugin-teardown-shape.mjs --self-test needs a deeper clone (the same exit 3 on the main base d7f299c); check:skill-examples needs @objectstack/client-react built; check:dual-build-cjs-loads needs every package's dist. These are left to CI.
  • dispatch-gates --ran: 117 derived, 114 run, 3 NOT-MEASURED, 0 UNRUN.
  • After 3df745d only a test file and a TSDoc comment changed; the full set ran in CI at 6e978db (60 success, 10 skipped, 0 failed).
Ablations (scripts/ablation-replace.mjs; each mutation proven on disk and restored to the HEAD blob)
  • Memory adapter filter disabled (organizations forced undefined): 6 contract cases red (the 3 adapter-only filter cases, both service cases under isolated and group, and the upgrade case). Restored to blob 70dc64b28dca.
  • organizationId dropped from the hashed body: 2 red (the contract upgrade case, and the service hash pin). Restored to fe7502ad5613.
  • The service stops handing organizationIds to the adapter: 4 contract cases and 5 service cases red. Restored to fe7502ad5613.
  • The plugin's resolveTenancyPosture wiring replaced by async () => undefined: 3 service cases red (both walled kernel cases and the unreadable case); the no-tenancy case stays green. Restored.

Acceptance notes

  • K8 item 2's wording. It lists the hashed parts as "content, title, metadata". Here the hash also covers organizationId, but only when the document has one. Without that, a complete reindex would skip every document indexed before this change, and those documents would never gain their organization behind a wall. Documents without an organization keep their exact v1 hash. The contract review (7157191417, M1) asks for a dated note on ADR-0161 to land first; that note is PR docs(adr): ADR-0161 dated note — the document hash covers the organization of a document that has one (K8 items 2 and 9) #37263, merged first as 8032d958f2.
  • The object facts handed to computeTenantLayer0Verdict come from the engine's getSchema: tenancy.enabled: false or systemFields.tenant: false, and whether an organization_id field exists. Unknown schema means the object is treated as walled. External (federated) objects are not special-cased, so externalOrganizationScopeUndeclared is false. Platform-admin crossing is not applied to ranking (isPlatformAdmin: false). The re-read still decides access either way.
  • recordToDocument takes the posture as an optional fifth argument, so existing calls behave as before.
  • The system-context page's row 46 ("Knowledge search returns hits unfiltered, and searches every source") still describes the system bypass accurately: through admitSources, the same bypass now also skips the organization filter. The row's prose does not mention organizations. The page is outside this card's file surface, so it is left unchanged and its owner can choose to add that.

Verification

Two-minute check: pnpm --filter @objectstack/knowledge-memory exec vitest run src/__tests__/contract.test.ts should report 21 tests passed, including "isolated: a search from organization A never ranks or returns B's documents" and "group: …".

Read first:

  1. packages/services/service-knowledge/src/knowledge-organization-scope.ts: the posture-to-organizations mapping (risk: a wrong verdict input widens or empties the ranking scope).
  2. packages/services/service-knowledge/src/knowledge-service.ts: scopeByOrganization, plus computeDocHash / recordToDocument (risk: the hash change decides what a reindex rewrites).
  3. packages/plugins/knowledge-memory/src/index.ts, search (risk: filtering after scoring instead of before).

Generated by Claude Code

….organizationIds (ADR-0161 K8 item 9)

Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1
Co-authored-by: Claude <noreply@anthropic.com>
…mory adapter filters before ranking; contract cases

Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1
Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1
Co-authored-by: Claude <noreply@anthropic.com>
…ssion's one system bypass

Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation protocol:ai tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/knowledge-memory, @objectstack/service-knowledge, @objectstack/spec, touching 44 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/spec/authorable-surface/ai.json), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

35 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 9171bed0a65ab242567f243969368ead786cd830.

⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/spec/authorable-surface/ai.json) — pages documenting those are invisible to this run
  • 1 cross-cutting symbol(s) contributed no route anchor: userId (5 routes)
  • 1 anchor(s) matched too much of the corpus to be a work list: organization_id (literal, 42 pages)
  • 4 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 9171bed0a65ab242567f243969368ead786cd830 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 99f48902f4d11cae1fef938986d85c78bb8309b2 — the merge of head 6e978db363c73dc9d151549ef46d6c141bc679ac into base 9171bed0a65ab242567f243969368ead786cd830, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 99f48902f4d11cae1fef938986d85c78bb8309b2 && git checkout 99f48902f4d11cae1fef938986d85c78bb8309b2
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 9171bed0a65ab242567f243969368ead786cd830 6e978db363c73dc9d151549ef46d6c141bc679ac && git checkout -B drift-repro 9171bed0a65ab242567f243969368ead786cd830 && git merge --no-ff 6e978db363c73dc9d151549ef46d6c141bc679ac

node scripts/docs-audit/affected-docs.mjs --json 9171bed0a65ab242567f243969368ead786cd830

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 9171bed0a65ab242567f243969368ead786cd830 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 3df745d2a1328770687e0f93ecc5e7b5f29ca946
Local-runs: probe — the zone's ablation counts and the plugin-wiring pin could only be measured by running the two vitest suites at this head, in a throwaway worktree that is now removed
Scope: packages/spec/src/ai/knowledge-document.zod.ts, packages/spec/src/contracts/knowledge-adapter.ts + packages/services/service-knowledge/src/knowledge-organization-scope.ts, packages/services/service-knowledge/src/knowledge-service.ts, packages/services/service-knowledge/src/knowledge-service-plugin.ts, packages/services/service-knowledge/src/knowledge-source-admission.ts, packages/services/service-knowledge/src/testing.ts, packages/plugins/knowledge-memory/src/index.ts, packages/spec/authorable-surface/ai.json, content/docs/references/ai/knowledge-document.mdx, content/docs/protocol/knowledge.mdx

① Derived judgments

② Semver level

③ Boundary flags

  • Deviation "regenerated artifacts": accepted, both are generator output and check:generated is green in CI.
  • Deviation "knowledge-service-plugin.ts": verified, +20 lines, one import and one constructor option; the mount path and the embedder logic are not in the diff.
  • Deviation "no scripts/adr-anchors entry": accepted, outside the file surface (N4).
  • Deviation "16 of 117 gates re-run after the last two commits": accepted, CI ran the whole set at this head and is green.
  • Out-of-scope note on system-context.mdx row 46: agreed, no new row is owed (N1).
  • Open question (docHash recipe): answered below, option A, with M1.
  • SQL push-down (Prime Directive 5): no new in-app join or id materialisation where SQL could do it. The service hands the adapter the organization set, so a SQL adapter (knowledge-pgvector: an open vector store on PostgreSQL — tables, exact search, listing, chunks #37100) filters in its own WHERE; knowledge-memory is an in-process store and filters its own array.

④ Design judgment

Claims checked against the code at this head:

  1. Server-side computation holds. searchOrganizationIds feeds computeTenantLayer0Verdict from ctx.tenantId / ctx.accessible_org_ids and the posture from classifyAdmissionTenancyPosture; it maps the verdict and derives nothing. The object facts come from engine.getSchema, the same source plugin-security prefers for the wall's own field set. isPlatformAdmin and posturePermitsCrossTenant are passed false, which can only narrow.
  2. [] versus undefined holds, and I found no path where a caller behind a wall gets undefined that the wall itself would not also answer none. The exits that hand no filter are: the system identity; a file / http source; the single posture or no tenancy service; an object with tenancy disabled or with no organization_id column. No context or no engine drops every object source before the scope is asked. An unreadable posture drops them too. An unreadable schema reads as a walled object. deny maps to [].
  3. Input rejection holds: KnowledgeSearchOptions has no organization member, the adapter options are built fresh, a caller's filter.organizationIds stays inside filter (pinned), search_knowledge refuses the argument (pinned), indexDocument throws before the upsert (pinned).
  4. knowledge-memory filters the chunk list before the metadata filter and before scoring; applyPermissionFilter is not in the diff.
  5. The move in 44494ec2 is behaviour-preserving for every caller that is not the system identity: before it, scopeByOrganization skipped on !ctx || ctx.isSystem; after it, the system identity returns earlier and the no-context branch has already dropped the object sources. Every other caller still reaches scopeByOrganization.

Findings:

  • M1 (must-fix) — the hash recipe of K8 item 2 changes here without the dated note that K8 rule 3 names as the form of such a change. The note on ADR-0161 (items 2 and 9) lands first; this PR then proceeds unchanged on that point. Reason for the order: this PR lands on a review record, while docs/adr is the maintainer's to approve, so merging first would settle his decision for him, and a recipe that has shipped is costly to flip (each flip rewrites documents).
  • S1 (should-fix) — the plugin's resolveTenancyPosture wiring has no pin. Replacing it with async () => undefined in knowledge-service-plugin.ts leaves both suites green (29/29, 192/192). It is the only production reader of the posture; if it breaks, every deployment reads as single: no document is stamped and no filter is handed, silently. One plugin-level case over a kernel with a tenancy service (walled → the adapter is handed the set; none registered → no filter; registered and throwing → no object source searched) closes it.
  • S2 (should-fix) — the contract text does not say that an adapter storing docHash has to store organizationId from the same version on. K8 rule 2 lets an adapter take up item 2 before item 9. Such an adapter stores a hash that already covers the organization while holding no organization; when it later starts to read item 9, a complete reindex skips every document (the hashes match) and a walled search never ranks them. It fails toward ranking nothing, and it is the same under option B. One sentence on KnowledgeDocument.organizationId in the spec TSDoc, repeated in the dated note, is enough.
  • N1 — content/docs/permissions/system-context.mdx row 46 needs no new row: the bypass is the same admitSources read, no elevation site was added, and the census is green. Its prose could add that the system identity is also handed no organization scope; that is the page owner's call.
  • N2 — under single the function returns before the verdict is asked, so the outsideEveryOrganization input is never read (the walled rungs ignore it). A person outside every organization is therefore handed no filter where the verdict says deny; the re-read still returns nothing. Either let the verdict answer under single too, or drop the input.
  • N3 — the plugin types the tenancy service inline rather than as core's TenancyPostureSource, and its sync leg repeats the not-registered handling classifyAdmissionTenancyPosture already does.
  • N4 — no scripts/adr-anchors entry for K8 item 9; a follow-up outside this file surface.
  • N5 — an event sync whose posture read throws is logged at warn and leaves the stored document as it was; no case pins that path.
  • N6 — for service-knowledge: a source that was never built gets built, and an operator can start a rebuild #37099: a build that runs at boot before the tenancy service is registered reads "no wall" and stamps nothing. The next complete reindex repairs it (the hash differs), but the card should read the posture after the kernel is ready.

The docHash question: option A, and the ADR note lands before this PR.
Correctness. Under A the hash covers the organization whenever the document has one, so every change that should rewrite a document changes its hash: a document gaining an organization (the upgrade, or a deployment moving from single to a walled posture), losing one, or moving from one organization to another with no content change. A complete reindex therefore never leaves a stale stamp, with the one adapter-side exception S2 names, which B shares. Under B the first reindex after the version bump is correct, but nothing after it is: a record that moves organization, or a deployment that turns its wall on later, keeps its hash, the reindex skips it, and the stamp stays wrong until an event happens to touch that record. Reconcile exists because events are missed (K1), so B leaves a hole the reindex was built to close: the old organization keeps a ranking place the re-read empties, and the new one never sees the document ranked.
Contract fidelity. Item 2 decides "a hash of the assembled document"; the three parts in its parenthesis were the whole assembled document when it was accepted. Item 9 then makes the organization part of what the service sets at assembly. A keeps item 2's meaning and outdates its parenthesis; B keeps the parenthesis and gives up the meaning. The recipe is also not something an adapter reads: it stores the hash as given. So A is an amendment to the record, not a departure from the contract, and K8 rule 3 gives the form: a dated note.
Which is harder for AI-written code to get wrong. A keeps one rule, "the hash covers what the service assembled", and the suite holds it from both sides (the byte-for-byte pin of the old recipe, and the upgrade case). B adds a second rule a later author has to remember, "organization changes reach the index by events only", with nothing in the reindex path to fail when it is forgotten. A's one trap is the conditional inclusion: a later optional member has to enter the hash the same way (absent means omitted), or the version has to be bumped; the note should say so.
Order. Before. The note is the maintainer's decision on a governed path, and this PR would otherwise land without him and fix the recipe in shipped indexes. K = 0 and nothing else open touches these files, so waiting costs little.

Implemented-by: claude/issue-37097-knowledge-org-filter
Reviewed-by: session_01QSeKYpEsWWE9Y5YtSsDgqZ

VERDICT: FAIL

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

席位核对 — REWORK · L1 · head 3df745d2a1328770687e0f93ecc5e7b5f29ca946 · 2026-11-25T08:34Z

  • PR feat(service-knowledge): documents carry their organization, and search hands the adapter the caller's organizations #37256 (draft) for service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter #37097, epic 专题:知识检索平台化(应用写一份知识源配置就有可用的检索:开源、托管、企业版都能用) #37000, zone a4-K. Fixes #37097; Clause-②: yes; Metadata-protocol: added; Skills-docs: none with a reason that holds (no skill teaches the document shape, the search options, the hash or the suite).
  • Size: 15 files, +803/−44, as reported. Every file is inside the claimed surface; the two regenerated spec artifacts are generator output.
  • Changeset: spec minor, service-knowledge and knowledge-memory patch, the same levels as service-knowledge: adapters list their documents; a complete reindex skips unchanged documents and purges the ones its source no longer has; one contract test suite #37096's.
  • K = 0; git merge-tree against origin/main d62f9e9c05a4 is clean; mergeable_state: clean.
  • Check-runs at head, read 2026-11-25T08:31Z: 60 success, 10 skipped (opt-in and queue-only jobs), 0 failed, 0 running.
  • Local at head in a throwaway worktree (removed): knowledge-memory 29/29, service-knowledge 192/192, system-context census OK.
  • Acceptance: A never ranks B under isolated and group (adapter case and through-service case, both in the shared contract suite); single and the system identity are handed no filter. All present and green.
  • Zone claims 1 to 7 verified against the code; details in the contract review. In short: the organization set is the Layer 0 verdict over the caller's context and the classified posture; [] and undefined are kept apart end to end; no path hands a walled caller undefined that the wall would not also leave unscoped; both input refusals are pinned; the memory adapter filters before it scores and the permission re-read is untouched; the three ablation counts reproduce (6; 2; 4 + 5); the move under admitSources' bypass changes nothing for a caller that is not the system identity; the plugin diff is one option and one import.
  • system-context.mdx needs no new row.
  • Overlap: none. chore: version packages #35129 touches only CHANGELOG.md / package.json of the two packages.
  • Owed review tier: CONTRACT_REVIEW_TIER (schema face, the two spec files). Record written for this head: FAIL.
  • M1 (must-fix) — the docHash recipe of ADR-0161 K8 item 2 changes without its dated note. Option A is right; the note (items 2 and 9, Tier H for the maintainer) lands before this PR. No code change is asked on this point.
  • S1 (should-fix) — the plugin's resolveTenancyPosture wiring is unpinned: forcing it to undefined leaves both suites green, and with it the whole change is silently off in a real deployment. Add one plugin-level case.
  • S2 (should-fix) — say in the spec TSDoc that an adapter storing docHash stores organizationId from the same version on; otherwise an adapter that takes up item 9 later has every document skipped by the reindex and never ranked behind a wall.
  • N1 — row 46's prose could mention that the system identity is also handed no organization scope; the page owner's call.
  • N2 — under single the verdict is never asked, so the outsideEveryOrganization input is dead; harmless, the re-read returns nothing for that caller.
  • N3 — the plugin types the tenancy service inline instead of TenancyPostureSource.
  • N4 — no scripts/adr-anchors entry for K8 item 9; follow-up.
  • N5 — the event-sync path with an unreadable posture has no case.
  • N6 — carry to service-knowledge: a source that was never built gets built, and an operator can start a rebuild #37099: a boot-time build that runs before tenancy is registered stamps nothing.
  • Next: open the docs-only ADR note for the maintainer; send S1 and S2 back to the zone; re-review at the new head once the note has merged.

…the event sync on an unreadable posture; TSDoc on organizationId with docHash

Claude-Session: https://claude.ai/code/session_01QSeKYkS1d2QkEUgqhneuU1
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 6e978db363c73dc9d151549ef46d6c141bc679ac
Local-runs: probe — the new plugin describe and its ablation count could only be measured by running the service-knowledge suite at this head, in a throwaway worktree that is now removed
Scope: delta 3df745d2a132..6e978db363c7 (two commits) — packages/spec/src/ai/knowledge-document.zod.ts + packages/services/service-knowledge/src/tests/knowledge-service.test.ts, read against packages/services/service-knowledge/src/knowledge-service-plugin.ts, knowledge-service.ts and knowledge-organization-scope.ts (unchanged since record 7157191417)

Delta record. It continues the record at 3df745d2a132 (comment 7157191417); what that record verified and this one does not restate still stands, because no production file changed.

① Derived judgments

  • The delta is two commits. e8b0688fe86c adds 93 lines to knowledge-service.test.ts and 4 TSDoc lines to knowledge-document.zod.ts. 6e978db363c7 rewrites those TSDoc lines only (+3/−4, one file, inside one comment block). No .describe() text, no schema member, no production source and no generated artifact is in either commit; the PR's file list is the same 15 files.
  • All local runs below were made at 6e978db363c7 itself, so nothing rests on the earlier head. Had they been made at e8b0688fe86c they would carry over unchanged: the diff between the two heads is comment text.
  • Local at this head: service-knowledge 197/197 (192 + 5 new), knowledge-memory 29/29, pnpm check:system-context-census OK (202 sites, register matches).
  • The zone's ablation reproduces: the plugin's resolveTenancyPosture set to async () => undefined gives 3 red (both walled cases and the unreadable case) and leaves the no-tenancy case green, 194/197. Restored.
  • Probes of mine, each restored. Running the no-tenancy and the unreadable case on ObjectKernel instead of LiteKernel: both green, so the production kernel answers the two the same way. Removing the getServiceAsync leg from the wiring: 197/197 green (N7). Making the sync leg swallow every throw: 197/197 green (N7).
  • K = 5 against origin/main ede9b91f402b (merge-base still d62f9e9c05a4); git merge-tree is clean (tree 784154079e9e); none of the five commits touches a knowledge package, the two spec files or core's security or kernel code. GitHub reads mergeable_state: unknown on a draft.
  • Check-runs at this head, read 2026-11-25T09:35Z: 60 success, 10 skipped, 0 failed, 0 running. The skipped ten are the same opt-in and queue-only jobs as at the prior head.
  • The two failure rows at e8b0688fe86c (Test UI, TypeScript Type Check) are a cancel cascade and not a test result: they are the two aggregate jobs, they ran four seconds each at 2026-11-25T09:03:50Z, right after their shards were cancelled at 2026-11-25T09:03:46Z by the push of 6e978db363c7 (2026-11-25T09:00:32Z). 27 runs there are cancelled; no shard reads failure.
  • ADR note PR docs(adr): ADR-0161 dated note — the document hash covers the organization of a document that has one (K8 items 2 and 9) #37263 (docs-only, draft, head dd1756af23aa) is open and not merged, read 2026-11-25T09:35Z.

② Semver level

  • Unchanged from the prior record. The delta adds no member, changes no accept-set and no signature. organizationId keeps its .describe() text, so the generated reference page and authorable-surface/ai.json are untouched, and the changeset needs no edit.
  • Metadata-protocol: added, Clause-②: yes and Skills-docs: none hold as before.

③ Boundary flags

  • Author: objectstack-fleet[bot].
  • skipSystemValidation: true in the harness is a test-only setting. In ObjectKernel it gates two things, the pre-injection of in-memory fallbacks for core services and the missing-service validation; neither is on the path under test (tenancy is not a core-requirement service, and the plugin resolves it through ctx.getKernel().getServiceAsync). It masks no production path: the wiring that runs is the plugin's own, and my probe shows the same answers with the flag on for the no-tenancy and unreadable cases. The only other user in the tree is a plugin-auth test fixture.
  • The cases reach the production wiring. KnowledgeServicePlugin is constructed and booted by a real kernel; the service under test is the one the plugin registered, fetched from the kernel; only the adapter and the objectql and tenancy services are stand-ins. The ablation above is the proof: a mutation in knowledge-service-plugin.ts turns the cases red.
  • SQL push-down: nothing in the delta reads data.
  • Not done by the zone and accepted as carried: N2, N3, N4. Main was not merged; K = 5 with a clean merge-tree, so nothing is owed for that before the landing sync.

④ Design judgment

Prior items, by id:

  • S1 — closed. The describe "KnowledgeServicePlugin reads the tenancy posture from the kernel" drives the real plugin on LiteKernel and ObjectKernel: walled → the adapter is handed ['org_a']; no tenancy service → no organizationIds key; registered and throwing → [] and adapter.search not called. The mutation the finding named (async () => undefined) now fails three cases.
  • S2 — closed. The sentence at this head reads: "An adapter that stores docHash stores organizationId from the same version on; otherwise, once it starts reading this field, a complete reindex skips its documents and a walled search never ranks them." It is true to the code. computeDocHash includes organizationId whenever the document has one; the reindex skip compares the stored hash with the computed one and nothing else; so an adapter that kept the hash and dropped the organization has matching hashes, is skipped, and holds no organization for its own filter to match. It is also the wording of the note in docs(adr): ADR-0161 dated note — the document hash covers the organization of a document that has one (K8 items 2 and 9) #37263, so the two texts agree. The first version of the sentence (at e8b0688fe86c) said the same with the reason spelled out; the rewrite loses nothing a reader needs (N8).
  • N5 — closed. The new case pins the path: the posture read throws inside syncRecord, the catch logs at warn with the reason, and neither upsert nor delete is called.
  • N1, N2, N3, N4, N6 — carried unchanged; none is touched by the delta.

On N5's behaviour, warn and keep. It is safe as stated, with one consequence worth writing down. The row is re-read before the posture is read, so a row that is gone or no longer matches is still deleted from the index; only a row that still matches is kept as stored. That stored document can then be stale in content or in organization (the record was edited, or moved to another organization, while the posture was unreadable). A stale organization means the old organization's callers can still have the document take a ranking place; the permission re-read then returns nothing for them, so nothing is served across the wall, and the new organization does not see it ranked. The repair is the row's next event or a complete reindex (the hash differs). Both alternatives are worse: an upsert without the posture would write an unstamped document, and a delete would drop a document whose row still matches. A reindex under the same fault refuses to write, so the two paths agree. The gap is the same class as a missed event, which K1's reconcile exists for.

Findings:

Why M1 stays a grade and is not carried as a Waits-on: line.
contract-review.md sets the landing check as "the last same-shape record at the current head is a PASS at the owed tier, with no open finding of the first two grades". It has no conditional PASS. landing-operations.md §C gives Waits-on: one use: a PR parked in draft because its checks are red until a dependency or a main-red anchor is fixed, with Waits-on: main-red #n as the line. M1 is not a red check. It is a finding about this PR against the contract's own amendment rule, and its whole content is the order. A Waits-on: line is read by no check, workflow or queue guard, so a PASS carrying one would leave nothing between this PR and the queue while the maintainer's decision on docs/adr is still open; that is the outcome M1 exists to prevent. Kept as a grade, the existing landing check holds the PR without a new mechanism. The cost is small: when #37263 merges, a delta record at the then-current head closes M1 on the note's merged text alone, and with S1 and S2 closed nothing else stands in the way.

Implemented-by: claude/issue-37097-knowledge-org-filter
Reviewed-by: session_01QSeKYpEsWWE9Y5YtSsDgqZ

VERDICT: FAIL

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

席位核对 — REWORK · L1 · head 6e978db363c73dc9d151549ef46d6c141bc679ac · 2026-11-25T09:38Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 6e978db363c73dc9d151549ef46d6c141bc679ac
Local-runs: none
Scope: same-head close-out of M1. Read: the ADR-0161 note as merged on origin/main 8032d958f2f2 (PR #37263), against packages/spec/src/ai/knowledge-document.zod.ts and packages/services/service-knowledge/src/knowledge-service.ts at this head

Close-out record. It continues the delta record at this same head (comment 7158593765) and the record at 3df745d2a132 (comment 7157191417). The head has not moved, so what those two verified stands as written, including the local runs of the delta record; nothing was run for this one.

① Derived judgments

② Semver level

  • Unchanged. No commit since the delta record; Metadata-protocol: added, Clause-②: yes and Skills-docs: none hold as before.

③ Boundary flags

  • Author: objectstack-fleet[bot].
  • Nothing new. The note landed through its own PR on docs/adr; this PR still carries no ADR edit, so the two cannot collide, and the merge-tree confirms it.
  • Main is not merged into the branch. K = 8 with a clean merge-tree; the landing sync covers it.

④ Design judgment

Prior items, by id:

  • M1 — closed. The dated note that K8 rule 3 names as the form of a change to item 2 is on main as 8032d958f2f2, ahead of this PR, and it says what this PR's code does on all three points above. The order M1 asked for is now the order of main's history. No code change was asked and none was made.
  • S1, S2, N5 — closed in the delta record; unchanged.
  • N8 — withdrawn. The delta record read the note as saying "the same version of the adapter". The merged note says "from the same version on", the TSDoc's own words, so the two texts are identical and there is no difference to bring into line.
  • N7 — carried as written: the kernel cases do not tell the async leg from the sync leg. Follow-up, not owed here.
  • N1, N2, N3, N4, N6 — carried unchanged; N6 goes to service-knowledge: a source that was never built gets built, and an operator can start a rebuild #37099.

No new finding. The head did not move, and the eight commits on main since the merge-base reach none of this PR's files, so no closed item reopens.

Implemented-by: claude/issue-37097-knowledge-org-filter
Reviewed-by: session_01QSeKYpEsWWE9Y5YtSsDgqZ

VERDICT: PASS

No must-fix, no should-fix.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

席位核对 — ACCEPT · L1 · head 6e978db363c73dc9d151549ef46d6c141bc679ac · 2026-11-25T09:59Z

No must-fix, no should-fix.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Landing · 2026-11-25T10:01Z · PR #37256 at 6e978db363c73dc9d151549ef46d6c141bc679ac (card #37097).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 25, 2026 10:01
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 25, 2026
Any commits made after this event will not be merged.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 25, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ

Re-queue after a merge-queue kick · 2026-11-25T10:22Z · PR #37256, head 6e978db363c73dc9d151549ef46d6c141bc679ac (unchanged).

  • The kick: queue build ddc7339fc5, CI_FAILURE. One test failed, in Test Core (10/10) (job 139126248269): @objectstack/plugin-security's insert-check-post-image.test.ts, "the scoping field lands IN scope — admitted, and that value is what is stored". It ran 5028 ms against a 5 s timeout, just after a logged Acquire connection error: Error: aborted. Shards 3–6 were cancelled in the cascade.
  • Why it is not this PR's:
    • The diff touches only packages/spec, service-knowledge, knowledge-memory and docs. Nothing in plugin-security.
    • Test Core is green at this head.
  • Action: one re-queue as the flake's victim, with the head unchanged. If the same signature kicks it again, the seat stops and files the flake anchor card.
  • Records still at this head:
    • L1 ACCEPT: 7159080287
    • Contract review PASS: 7159069116

@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 25, 2026
Any commits made after this event will not be merged.
@github-actions

Copy link
Copy Markdown
Contributor

⛔ merge queue 构建失败 — 先分诊,再决定要不要重排

队列构建 45590970668 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集),
所以失败的测试可能在本 PR 没碰过的包里 —— 那不是重排能修的。每次盲目重排都会让排在后面的所有 PR 重建一轮。

分类:failure —— 按下面的日志分诊。

失败的 job(日志抽取,best effort):

  • Test Core (10/10) — 失败步骤: Run this shard's tests

    @objectstack/plugin-security:test:  FAIL  src/insert-check-post-image.test.ts > [#16608] insert on driver-sqlite-wasm (:memory:) — the check judges the row that will be stored > the scoping field land
      ↳ 失败原因: @objectstack/plugin-security:test: Error: Test timed out in 5000ms.
    

↳ 失败原因 是判读的关键:超时(Test timed out in … / Hook timed out in …)多半是负载/时序,不是本 PR 的回归;
断言(AssertionError: …)才指向真实的行为改变。两者的 FAIL 行长得一模一样,只有这一行能区分。

⚠️ 断言这一侧有一类例外,判据是断言在测什么,不是它是不是 AssertionError。 断言的对象是产品行为(一个值、一个形状、一次拒收)⇒ 照上面读:真实的行为改变,去查,⛔ 不要重排掉;
断言的对象是这次实验自身的有效性前提(跑完的耗时、负载下的先后、任何只在时间预算内才成立的条件)⇒ 它跟超时是同一类,同样对负载敏感,重排一次是合法的判别手段。
识别是机械的:断言的消息或它比较的值本身点名了一段时长、一个时间戳、一个耗时计数。实测过的一对 —— AssertionError: SecurityPlugin.init() ran: expected false to be true 测的是产品行为(真回归);
AssertionError: this run took over a second, so second-precision stamps could have differed too: expected 1006 to be less than 1000 测的是实验前提:它守护的那条不变式当时是绿的,同一个 head 原样重排一次即成功。
穿着 AssertionError 外衣的时间测量,仍然是时间测量。(⛔ 这只改「怎么读一次红」,不改「哪些测试可以重排」——后者由别处管。)

跨 PR 相同签名(24h,按失败测试文件聚合):

  • src/insert-check-post-image.test.ts — 24h 窗口内只有本 PR 撞到过,暂不汇总(再有一个不同 PR 撞到就会自动开汇总 issue)。
  • ⚠️ 24h 评论账本没读完(超过 5 页仍未读到窗口尽头),所以上面的「不同 PR 数」是下界,不是全量。

历史信号:

  • 本 PR 过去 24h 无队列失败记录(首次)。
  • 过去 24h 队列共有 4 个失败构建(不含本次)。

分诊清单:

  1. 失败测试在本 PR 改动的包里 → 真回归,修 PR。
  2. 失败测试与本 PR 无关 → 看上面的「跨 PR 相同签名」;已有汇总 issue ⇒ flaky/环境问题实锤,去那张 issue 上谈,修好前重排只会再烧一轮全队列。
  3. 两者都不是 → 可能与同组 PR 语义冲突;等前面的 PR 落地或失败出队后再重排一次即可,不要连续重排。

Generated by Claude Code · merge-queue-triage workflow (#4859)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:ai size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

service-knowledge: documents carry their organization, and search hands the caller's organizations to the adapter

2 participants